package com.mybed.crm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mybed.crm.pojo.dto.AssignmentDto;
import com.mybed.crm.pojo.dto.PageBusinessDto;
import com.mybed.crm.pojo.dto.PageReportContractDto;
import com.mybed.crm.pojo.pojo.Business;
import com.mybed.crm.pojo.pojo.BusinessRecord;
import com.mybed.crm.pojo.pojo.Contract;
import com.mybed.crm.pojo.vo.BusinessRecordVo;
import com.mybed.crm.pojo.vo.IndexStatisticsVo;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.sql.Wrapper;
import java.util.List;
import java.util.Map;

@Mapper
//商机管理
public interface BusinessMapper extends BaseMapper<Business> {

    /**
     * 分页查询
     * @param page
     * @param pageBusinessDto
     * @return
     */
    IPage<Business> pageBusinessQuery(IPage<Business> page, Wrapper wrapper,@Param("pbd") PageBusinessDto pageBusinessDto);

    /**
     * 公海池的分页查询
     * @param page
     * @param pageBusinessDto
     * @return
     */
    IPage<Business> pageBusinessSeaQuery(IPage<Business> page, Wrapper wrapper, @Param("pbd") PageBusinessDto pageBusinessDto);

    /**
     * 新增商机
     * @param business
     */
    void addBusiness(Business business);

    /**
     * 根据id查询商机
     * @param id
     */
    Business selectBusinessId(Long id);


    /**
     * 跟进更改商机数据
     * @param businessRecord
     */
    void addRecord(BusinessRecord businessRecord);

    /**
     * 查询跟进后的数据
     * @param businessId
     */
    List<BusinessRecordVo> selectRecord(Long businessId);

    List<String> selectKey(List<String> list);

    /**
     * 踢回公海
     * @param id
     * @return
     */
    void updateBusinessStatus(Integer id);

    /**
     * 商机分配
     * @param assignmentDto
     */
    void updateBusinessUserId(AssignmentDto assignmentDto);

    //商机龙虎榜 -统计总数
    int countAllBusiness(String beginCreateTime, String endCreateTime);

    //商机龙虎榜 -统计每个业务员商机数量
    @MapKey("userId")
    List<Map<String, Object>> countAllContractByUser(IndexStatisticsVo request);



    void updateBusinessStatusId(Business business);
}
